/**   
 * @Title: ParticleCanvs.java 
 * @Package com.forever.thread.gui 
 * @Description: TODO(用一句话描述该文件做什么) 
 * @author leo   
 * @date 2014-9-16 上午11:17:03
 */
package com.forever.thread.gui;

import java.awt.Canvas;
import java.awt.Dimension;
import java.awt.Graphics;
import java.io.Serializable;

/**
 * @ClassName: ParticleCanvs
 * @Description: TODO(这里用一句话描述这个类的作用)
 * @author leo
 * @date 2014-9-16 上午11:17:03
 * 
 */
@SuppressWarnings("serial")
public class ParticleCanvs extends Canvas implements Serializable {

	private Particle[] particles = new Particle[0];

	/**
	 * 
	 */
	protected ParticleCanvs(int size) {
		setSize(new Dimension(size, size));
	}

	protected synchronized void particles(Particle[] ps) {
		if (null == ps) {
			throw new IllegalArgumentException("can not set null");
		}
		particles = ps;
	}

	protected synchronized Particle[] getParticles() {
		return particles;
	}

	public void paint(Graphics graphics) {
		Particle[] ps = getParticles();
		for (int i = 0; i < ps.length; i++) {
			ps[i].draw(graphics);
		}
	}

	public void setParticles(Particle[] particles) {
		this.particles = particles;
	}
}